package com.qf.utils;

import com.qf.pojo.reqVo.LiveUserReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * 邮件发送的工具类
 */
@Component
public class EmailUtils {

    @Autowired
    JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String from;

    public String sendMail(String email){
        //进行邮件的发送
        try {
            SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
            simpleMailMessage.setFrom(from);
            simpleMailMessage.setTo(email);
            simpleMailMessage.setSubject("千锋教育平台言验证码");
            //验证码生成
            StringBuffer stringBuffer = new StringBuffer();
            for (int i=0;i<=4;i++){
                int i1 = new Random().nextInt(10);
                stringBuffer.append(i1);
            }
            simpleMailMessage.setText(stringBuffer.toString());
            javaMailSender.send(simpleMailMessage);

            return stringBuffer.toString();
        }catch (Exception e){
            return null;
        }


    }


}
